﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Engine.UI;

/// <summary>
/// 提示面板
/// </summary>
public class TipView : ViewBase
{
    /// <summary>
    /// 提示标题
    /// </summary>
    private Text title;
    /// <summary>
    /// 提示内容
    /// </summary>
    private Text content;

    /// <summary>
    /// 按钮0
    /// </summary>
    private Button btn0;

    /// <summary>
    /// 按钮1
    /// </summary>
    private Button btn1;
    private string tipString = null;

    public override string GetPath()
    {
        return "lobby.ui.tipview";
    }

    //初始化
    public override void OnLoaded(Transform prefab)
    {
        base.OnLoaded(prefab);
        title = prefab.Find("Title").GetComponent<Text>();
        content = prefab.Find("Content").GetComponent<Text>();
        content.text = "";
        btn0 = prefab.Find("Btns/0").GetComponent<Button>();
        btn0.onClick.AddListener(OnClose);
        btn1 = prefab.Find("Btns/1").GetComponent<Button>();
        btn1.onClick.AddListener(OnClose);
    }

    public void SetTip(string tip)
    {
        tipString = tip;
        InvalidData();
    }

    public override void DataUpdate()
    {
        base.DataUpdate();
        if (tipString != null)
        {
            content.text = tipString;
        }
        else
        {
            Log.Warning("tipString == null");
        }
        Close(1.5f);
    }

    public void ShowOne(UnityAction a)
    {
        btn0.onClick.AddListener(a);
        btn1.gameObject.SetActive(false);
    }

    public void ShowTwo(UnityAction a, UnityAction b)
    {
        btn0.onClick.AddListener(a);
        btn1.onClick.AddListener(b);
    }

    public void OnClose()
    {
        Close();
    }
}